var wall = document.getElementById('wall');
var item = document.getElementsByClassName('item');
function pbl(){
	var clientWidth = document.documentElement.clientWidth|document.body.clientWidth;
	var num = Math.floor(clientWidth/item[0].offsetWidth);
	wall.style.width = num * item[0].offsetWidth+'px';
	var height = [];
	
	for (var i = 0;i<item.length;i++) {
//		console.log(item[2].offsetHeight)
		if(i<num){
			height.push(item[i].offsetHeight);
		}else{
			var minHeight = Math.min.apply(null,height);
			var index = height.indexOf(minHeight);
//			console.log(index)
//			console.log(height)
			item[i].style.position = 'absolute';
			item[i].style.index = '1'
			item[i].style.top = minHeight+'px';
			item[i].style.left = item[index].offsetLeft+'px';
			height[index] += item[i].offsetHeight;
		}
	}
}
pbl()